package com.xbongbong.paas.script.controller;

import com.alibaba.fastjson.JSON;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.PaasUserEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasUserModel;
import com.xbongbong.paas.pojo.dto.TeamMembersDTO;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.redis.RedisPrefixConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.JsonHelperUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.pro.config.ProBaseConfig;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formdata.pojo.PaasFormDataNoDataPojo;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.domain.entity.UserTeamEntity;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import com.xbongbong.saas.enums.business.PayPlanEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.business.PaymentEnum;
import com.xbongbong.saas.enums.business.PaymentSheetEnum;
import com.xbongbong.saas.enums.business.SupplierContactEnum;
import com.xbongbong.saas.model.PaasFormDataModel;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.saas.script.tempenum.TempContactEnum;
import com.xbongbong.saas.script.tempenum.TempPayPlanEnum;
import com.xbongbong.saas.script.tempenum.TempPaySheetEnum;
import com.xbongbong.saas.script.tempenum.TempPaymentEnum;
import com.xbongbong.saas.script.tempenum.TempPaymentSheetEnum;
import com.xbongbong.saas.script.tempenum.TempSupplierContactEnum;
import com.xbongbong.sys.enums.RoleEnum;
import com.xbongbong.sys.model.CompanyConfigModel;
import com.xbongbong.sys.model.UserModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author: 汪腾伟
 * @date: Created in 2021/12/6 14:33
 * @description： 团队成员脚本Controller层
 */
@RestController
@RequestMapping(XbbProConstant.API_ROOT_PREFIX + "/script/teamMembers")
public class TeamMembersScriptController {
    private static final Logger LOG = LoggerFactory.getLogger(TeamMembersScriptController.class);

    @Resource
    private ProBaseConfig proBaseConfig;
    @Resource
    private PaasRedisHelper paasRedisHelper;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private PaasFormDataModel paasFormDataModel;
    @Resource
    private UserModel userModel;
    @Resource
    private PaasUserModel paasUserModel;
    @Resource
    private CompanyConfigModel companyConfigModel;

    /**
     * 修改某些业务的协同字段和负责人字段
     *     应收款：协同人需要显示
     *     回款单：负责人、协同人需要显示
     *     付款单：负责人、协同人字段需要显示
     *
     * @param teamMembersDTO
     * @return
     */
    @RequestMapping(value = "/explains/fixTeamMembersField", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fixTeamMembersField(@RequestBody @Valid TeamMembersDTO teamMembersDTO) throws XbbException {
        try {
            if (!proBaseConfig.getXbbCode().equals(teamMembersDTO.getXbbCode())) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100006);
            }
            LOG.warn("-----------fixTeamMembersField start 开始执行修改团队成员某些业务的协同人字段、负责人字段解释-----------");
            long timeStart = DateTimeUtil.getInt();
            Integer fullFlag = teamMembersDTO.getFullFlag();
            List<String> corpidList = teamMembersDTO.getCorpidList();
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put("del", BasicConstant.ZERO);
            if (Objects.equals(fullFlag, BasicConstant.ZERO)) {
                if (CollectionsUtil.isEmpty(corpidList)) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100006, "corpidList不能为空，请传入要部分提前处理的公司id集合");
                }
                param.put("corpidIn", corpidList);
            }
            Integer businessTypePayment = XbbRefTypeEnum.PAYMENT.getCode();
            Integer businessTypePaymentSheet = XbbRefTypeEnum.PAYMENT_SHEET.getCode();
            Integer businessTypePaySheet = XbbRefTypeEnum.PAY_SHEET.getCode();
            Integer busienssTypePayPlan = XbbRefTypeEnum.PAY_PLAN.getCode();
            Integer businessTypeContact = XbbRefTypeEnum.CONTACT.getCode();
            Integer businessTypeSupplierContact = XbbRefTypeEnum.SUPPLIER_CONTACT.getCode();
            List<Integer> businessTypeList = Arrays.asList(businessTypePayment, businessTypePaymentSheet, businessTypePaySheet,
                    busienssTypePayPlan, businessTypeContact, businessTypeSupplierContact);
            //需要新增的一些业务的字段，付款计划协同人字段，联系人、供应商联系人协同人字段,
            PayPlanEnum payPlanCoUserField = PayPlanEnum.COUSERID;
            Class<PayPlanEnum> payPlanEnumClass = PayPlanEnum.class;
            List<String> payPlanEnumAttrs = InitExplainsHelper.getBusinessEnumAttrs(payPlanEnumClass);
            FieldAttrEntity newFieldAttrEntityPlanCouser = InitExplainsHelper.setField(payPlanEnumClass, payPlanEnumAttrs, payPlanCoUserField);
            TempPayPlanEnum.initCoUserId(newFieldAttrEntityPlanCouser);

            ContactEnum contactCouserField = ContactEnum.COUSERID;
            Class<ContactEnum> contactEnumClass = ContactEnum.class;
            List<String> contactEnumAttrs = InitExplainsHelper.getBusinessEnumAttrs(contactEnumClass);
            FieldAttrEntity newFieldAttrEntityContactCouser = InitExplainsHelper.setField(contactEnumClass, contactEnumAttrs, contactCouserField);
            TempContactEnum.initCoUserId(newFieldAttrEntityContactCouser);

            SupplierContactEnum supplierContactCouserField = SupplierContactEnum.COUSERID;
            SupplierContactEnum supplierContactOwnerField = SupplierContactEnum.OWNER_ID;
            Class<SupplierContactEnum> supplierContactEnumClass = SupplierContactEnum.class;
            List<String> supplierContactEnumAttrs = InitExplainsHelper.getBusinessEnumAttrs(supplierContactEnumClass);
            FieldAttrEntity newFieldAttrEntitySupplierContactCouser = InitExplainsHelper.setField(supplierContactEnumClass, supplierContactEnumAttrs, supplierContactCouserField);
            FieldAttrEntity newFieldAttrEntitySupplierContactOwner = InitExplainsHelper.setField(supplierContactEnumClass, supplierContactEnumAttrs, supplierContactOwnerField);
            TempSupplierContactEnum.initCoUserId(newFieldAttrEntitySupplierContactCouser);
            TempSupplierContactEnum.initOwnerId(newFieldAttrEntitySupplierContactOwner);

            //移除默认解释缓存
            removeDefaultExplainRedis(businessTypeList);
            param.put("businessTypeIn", businessTypeList);
            //只处理非经销商的
            param.put("distributorMark", DistributorMarkEnum.OTHER.getCode());
            Long maxId = paasFormExplainModel.getMaxId(param);
            Integer start = 0;
            //每次查询200条
            Integer pageNum = 200;
            Long idGte = 0L;
            param.put("start", start);
            param.put("pageNum", pageNum);
            param.put("orderByStr", "id asc");
            while (true) {
                param.put("idGte", idGte);
                LOG.warn("处理进度：已处理到 tb_paas_form_explain.id {} / {}", idGte, maxId);
                //表单解释列表
                List<PaasFormExplainEntity> explainList = paasFormExplainModel.list(param);
                if (CollectionsUtil.isEmpty(explainList)) {
                    break;
                }
                List<PaasFormExplainEntity> updateExplains = new ArrayList<>();
                idGte = explainList.get(explainList.size() - 1).getId();
                for (PaasFormExplainEntity explainEntity : explainList) {
                    //全量执行时，剔除已经处理过的公司id集合
                    if (Objects.equals(fullFlag, BasicConstant.ONE) && CollectionsUtil.isNotEmpty(corpidList) && corpidList.contains(explainEntity.getCorpid())) {
                        continue;
                    }
                    if (StringUtil.isEmpty(explainEntity.getExplains()) || Objects.equals("[]", explainEntity.getExplains())) {
                        //代表该公司用的是默认缓存
                        continue;
                    }
                    List<FieldAttrEntity> fieldAttrList = JsonHelperUtil.parseArray(explainEntity.getExplains(), FieldAttrEntity.class);
                    if (CollectionsUtil.isEmpty(fieldAttrList)) {
                        continue;
                    }
                    if (Objects.equals(explainEntity.getBusinessType(), businessTypePayment)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, PaymentEnum.COUSERID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ZERO);
                                //这个代表校验必填不置灰
                                fieldAttrEntity.setSetType(SetTypeEnum.DISABLE_REPEAT.getCode());
                                TempPaymentEnum.initCoUserId(fieldAttrEntity);
                            }else if (Objects.equals(attr, PaymentEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ZERO);
                                fieldAttrEntity.setRequired(BasicConstant.ONE);
                                fieldAttrEntity.setShowType(ShowTypeEnum.ALL.getCode());
                                fieldAttrEntity.setIsForbidden(BasicConstant.ZERO);
                                //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
                                fieldAttrEntity.setShowEditable(0);
                                fieldAttrEntity.setAdd(1);
                                fieldAttrEntity.setAddAdvanceEnable(1);
                                fieldAttrEntity.setShowAdd(1);
                                //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
                                fieldAttrEntity.setRemove(1);
                                fieldAttrEntity.setRemoveAdvanceEnable(1);
                                fieldAttrEntity.setShowRemove(1);
                                fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
                                fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
                            }
                        }
                    }else if (Objects.equals(explainEntity.getBusinessType(), businessTypePaymentSheet)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, PaymentSheetEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setRequired(BasicConstant.ONE);
                                fieldAttrEntity.setEditHide(BasicConstant.ZERO);
                                TempPaymentSheetEnum.initOwnerId(fieldAttrEntity);
                            }else if (Objects.equals(attr, PaymentSheetEnum.COUSERID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ZERO);
                                fieldAttrEntity.setSetType(SetTypeEnum.DISABLE_REPEAT.getCode());
                                TempPaymentSheetEnum.initCoUserId(fieldAttrEntity);
                            }
                        }
                    }else if (Objects.equals(explainEntity.getBusinessType(), businessTypePaySheet)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, PaySheetEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ZERO);
                                fieldAttrEntity.setRequired(BasicConstant.ONE);
                                TempPaySheetEnum.initOwnerId(fieldAttrEntity);
                            }else if (Objects.equals(attr, PaySheetEnum.COUSERID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ZERO);
                                fieldAttrEntity.setSetType(SetTypeEnum.DISABLE_REPEAT.getCode());
                                TempPaySheetEnum.initCoUserId(fieldAttrEntity);
                            }
                        }
                    }else if (Objects.equals(explainEntity.getBusinessType(), busienssTypePayPlan)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, PayPlanEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ZERO);
                                //因为付款计划的负责人字段是放出来的，所以这边需要一个一个自己拼参数
                                fieldAttrEntity.setRequired(BasicConstant.ONE);
                                fieldAttrEntity.setShowType(ShowTypeEnum.ALL.getCode());
                                //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
                                fieldAttrEntity.setShowEditable(0);
                                fieldAttrEntity.setAdd(1);
                                fieldAttrEntity.setAddAdvanceEnable(1);
                                fieldAttrEntity.setShowAdd(1);
                                //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
                                fieldAttrEntity.setRemove(1);
                                fieldAttrEntity.setRemoveAdvanceEnable(1);
                                fieldAttrEntity.setShowRemove(1);
                                fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
                                fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
                            }
                        }
                        Iterator<FieldAttrEntity> fieldAttrEntityIterator =  fieldAttrList.iterator();
                        while (fieldAttrEntityIterator.hasNext()) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrEntityIterator.next();
                            if (Objects.equals(fieldAttrEntity.getAttr(), PayPlanEnum.COUSERID.getAttr())) {
                                fieldAttrEntityIterator.remove();
                            }
                        }
                        fieldAttrList.add(newFieldAttrEntityPlanCouser);
                    }else if (Objects.equals(explainEntity.getBusinessType(), businessTypeContact)) {
                       for (int i = 0; i < fieldAttrList.size(); i++) {
                           FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                           String attr = fieldAttrEntity.getAttr();
                           if (Objects.equals(attr, ContactEnum.OWNER_ID.getAttr())) {
                               TempContactEnum.initOwnerId(fieldAttrEntity);
                           }
                       }
                        Iterator<FieldAttrEntity> fieldAttrEntityIterator =  fieldAttrList.iterator();
                        while (fieldAttrEntityIterator.hasNext()) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrEntityIterator.next();
                            if (Objects.equals(fieldAttrEntity.getAttr(), ContactEnum.COUSERID.getAttr())) {
                                fieldAttrEntityIterator.remove();
                            }
                        }
                        fieldAttrList.add(newFieldAttrEntityContactCouser);
                    }else if (Objects.equals(explainEntity.getBusinessType(), businessTypeSupplierContact)) {
                        //这边因为测试环境发现脏数据，所以这边负责人修改的策略就改成先移除然后再增加
                       /* for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, ContactEnum.OWNER_ID.getAttr())) {
                                TempSupplierContactEnum.initOwnerId(fieldAttrEntity);
                            }
                        }*/
                        Iterator<FieldAttrEntity> fieldAttrEntityIterator =  fieldAttrList.iterator();
                        while (fieldAttrEntityIterator.hasNext()) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrEntityIterator.next();
                            if (Objects.equals(fieldAttrEntity.getAttr(), SupplierContactEnum.COUSERID.getAttr())) {
                                fieldAttrEntityIterator.remove();
                            }else if (Objects.equals(fieldAttrEntity.getAttr(), SupplierContactEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntityIterator.remove();
                            }
                        }
                        fieldAttrList.add(newFieldAttrEntitySupplierContactCouser);
                        fieldAttrList.add(newFieldAttrEntitySupplierContactOwner);
                    }

                    String explains = JSON.toJSONString(fieldAttrList);
                    explainEntity.setExplains(explains);
                    updateExplains.add(explainEntity);
                }
                if (CollectionsUtil.isNotEmpty(updateExplains)) {
                    paasFormExplainModel.updateBatchExplains(updateExplains);
                }
            }
            LOG.warn("-----------time consume fixTeamMembersField:{}", (DateTimeUtil.getInt() - timeStart));
            LOG.warn("-----------/script/fund/sheet/explains/fixTeamMembersField over");
        }catch (Exception e) {
            LOG.error("/script/fund/sheet/explains/fixTeamMembersField error", e);
        }
        return JSON.toJSONString("{\"msg\":\"success\"}");
    }


    /**
     * 修改某些业务的协同字段和负责人字段
     *     应收款：协同人需要显示
     *     回款单：负责人、协同人需要显示
     *     付款单：负责人、协同人字段需要显示
     *
     * @param teamMembersDTO
     * @return
     */
    @RequestMapping(value = "/explains/rollBackFixTeamMembersField", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String rollBackFixTeamMembersField(@RequestBody @Valid TeamMembersDTO teamMembersDTO) throws XbbException {
        try {
            if (!proBaseConfig.getXbbCode().equals(teamMembersDTO.getXbbCode())) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100006);
            }
            LOG.warn("-----------rollBackFixTeamMembersField start 开始执行回滚团队成员某些业务的协同人字段、负责人字段解释-----------");
            long timeStart = DateTimeUtil.getInt();
            Integer fullFlag = teamMembersDTO.getFullFlag();
            List<String> corpidList = teamMembersDTO.getCorpidList();
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            param.put("del", BasicConstant.ZERO);
            if (Objects.equals(fullFlag, BasicConstant.ZERO)) {
                if (CollectionsUtil.isEmpty(corpidList)) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100006, "corpidList不能为空，请传入要部分提前处理的公司id集合");
                }
                param.put("corpidIn", corpidList);
            }
            Integer businessTypePayment = XbbRefTypeEnum.PAYMENT.getCode();
            Integer businessTypePaymentSheet = XbbRefTypeEnum.PAYMENT_SHEET.getCode();
            Integer businessTypePaySheet = XbbRefTypeEnum.PAY_SHEET.getCode();
            Integer busienssTypePayPlan = XbbRefTypeEnum.PAY_PLAN.getCode();
            Integer businessTypeContact = XbbRefTypeEnum.CONTACT.getCode();
            Integer businessTypeSupplierContact = XbbRefTypeEnum.SUPPLIER_CONTACT.getCode();
            List<Integer> businessTypeList = Arrays.asList(businessTypePayment, businessTypePaymentSheet, businessTypePaySheet,
                    busienssTypePayPlan, businessTypeContact, businessTypeSupplierContact);
            //移除默认解释缓存
            removeDefaultExplainRedis(businessTypeList);
            param.put("businessTypeIn", businessTypeList);
            //只处理非经销商的
            param.put("distributorMark", DistributorMarkEnum.OTHER.getCode());
            Long maxId = paasFormExplainModel.getMaxId(param);
            Integer start = 0;
            //每次查询200条
            Integer pageNum = 200;
            Long idGte = 0L;
            param.put("start", start);
            param.put("pageNum", pageNum);
            param.put("orderByStr", "id asc");
            while (true) {
                param.put("idGte", idGte);
                LOG.warn("处理进度：已处理到 tb_paas_form_explain.id {} / {}", idGte, maxId);
                //表单解释列表
                List<PaasFormExplainEntity> explainList = paasFormExplainModel.list(param);
                if (CollectionsUtil.isEmpty(explainList)) {
                    break;
                }
                List<PaasFormExplainEntity> updateExplains = new ArrayList<>();
                idGte = explainList.get(explainList.size() - 1).getId();
                for (PaasFormExplainEntity explainEntity : explainList) {
                    //全量执行时，剔除已经处理过的公司id集合
                    if (Objects.equals(fullFlag, BasicConstant.ONE) && CollectionsUtil.isNotEmpty(corpidList) && corpidList.contains(explainEntity.getCorpid())) {
                        continue;
                    }
                    if (StringUtil.isEmpty(explainEntity.getExplains()) || Objects.equals("[]", explainEntity.getExplains())) {
                        //代表该公司用的是默认缓存
                        continue;
                    }
                    List<FieldAttrEntity> fieldAttrList = JsonHelperUtil.parseArray(explainEntity.getExplains(), FieldAttrEntity.class);
                    if (CollectionsUtil.isEmpty(fieldAttrList)) {
                        continue;
                    }
                    if (Objects.equals(explainEntity.getBusinessType(), businessTypePayment)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, PaymentEnum.COUSERID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ONE);
                                fieldAttrEntity.setSetType(SetTypeEnum.DISABLE_ALL.getCode());
                                fieldAttrEntity.setShowType(ShowTypeEnum.LIST_DETAIL.getCode());
                                fieldAttrEntity.setFormPermission(null);
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }else if (Objects.equals(attr, PaymentEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setRequired(BasicConstant.ZERO);
                                fieldAttrEntity.setShowType(ShowTypeEnum.LIST_DETAIL.getCode());
                                fieldAttrEntity.setIsForbidden(null);
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }
                        }
                    }else if (Objects.equals(explainEntity.getBusinessType(), businessTypePaymentSheet)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, PaymentSheetEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ONE);
                                fieldAttrEntity.setIsForbidden(null);
                                fieldAttrEntity.setRequired(BasicConstant.ZERO);
                                fieldAttrEntity.setShowType(ShowTypeEnum.LIST_DETAIL.getCode());
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }else if (Objects.equals(attr, PaymentSheetEnum.COUSERID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ONE);
                                fieldAttrEntity.setIsForbidden(null);
                                fieldAttrEntity.setShowType(ShowTypeEnum.LIST_DETAIL.getCode());
                                fieldAttrEntity.setSetType(SetTypeEnum.DISABLE_ALL.getCode());
                                fieldAttrEntity.setFormPermission(null);
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }
                        }
                    }else if (Objects.equals(explainEntity.getBusinessType(), businessTypePaySheet)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, PaySheetEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ONE);
                                fieldAttrEntity.setRequired(BasicConstant.ZERO);
                                fieldAttrEntity.setShowType(ShowTypeEnum.LIST_DETAIL.getCode());
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }else if (Objects.equals(attr, PaySheetEnum.COUSERID.getAttr())) {
                                fieldAttrEntity.setEditHide(BasicConstant.ONE);
                                fieldAttrEntity.setFormPermission(null);
                                fieldAttrEntity.setSetType(SetTypeEnum.DISABLE_ALL.getCode());
                                fieldAttrEntity.setShowType(ShowTypeEnum.LIST_DETAIL.getCode());
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }
                        }
                    }else if (Objects.equals(explainEntity.getBusinessType(), busienssTypePayPlan)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, PayPlanEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setRequired(BasicConstant.ZERO);
                                fieldAttrEntity.setShowType(ShowTypeEnum.LIST_DETAIL.getCode());
                                //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }
                        }
                        Iterator<FieldAttrEntity> fieldAttrEntityIterator =  fieldAttrList.iterator();
                        while (fieldAttrEntityIterator.hasNext()) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrEntityIterator.next();
                            if (Objects.equals(fieldAttrEntity.getAttr(), PayPlanEnum.COUSERID.getAttr())) {
                                fieldAttrEntityIterator.remove();
                            }
                        }
                    }else if (Objects.equals(explainEntity.getBusinessType(), businessTypeContact)) {
                        for (int i = 0; i < fieldAttrList.size(); i++) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrList.get(i);
                            String attr = fieldAttrEntity.getAttr();
                            if (Objects.equals(attr, ContactEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setShowType(ShowTypeEnum.NONE.getCode());
                                fieldAttrEntity.setEditHide(1);
                                fieldAttrEntity.setRequired(0);
                                //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setMultiple(null);
                                fieldAttrEntity.setIsForbidden(null);
                                fieldAttrEntity.setEditable(null);
                                fieldAttrEntity.setUnableEditMemo(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }
                        }
                        Iterator<FieldAttrEntity> fieldAttrEntityIterator =  fieldAttrList.iterator();
                        while (fieldAttrEntityIterator.hasNext()) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrEntityIterator.next();
                            if (Objects.equals(fieldAttrEntity.getAttr(), ContactEnum.COUSERID.getAttr())) {
                                fieldAttrEntityIterator.remove();
                            }
                        }
                    }else if (Objects.equals(explainEntity.getBusinessType(), businessTypeSupplierContact)) {
                        Iterator<FieldAttrEntity> fieldAttrEntityIterator =  fieldAttrList.iterator();
                        while (fieldAttrEntityIterator.hasNext()) {
                            FieldAttrEntity fieldAttrEntity = fieldAttrEntityIterator.next();
                            if (Objects.equals(fieldAttrEntity.getAttr(), SupplierContactEnum.COUSERID.getAttr())) {
                                fieldAttrEntityIterator.remove();
                            }else if (Objects.equals(fieldAttrEntity.getAttr(), SupplierContactEnum.OWNER_ID.getAttr())) {
                                fieldAttrEntity.setShowType(ShowTypeEnum.NONE.getCode());
                                fieldAttrEntity.setEditHide(1);
                                fieldAttrEntity.setRequired(0);
                                //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
                                fieldAttrEntity.setShowEditable(null);
                                fieldAttrEntity.setAdd(null);
                                fieldAttrEntity.setAddAdvanceEnable(null);
                                fieldAttrEntity.setShowAdd(null);
                                //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
                                fieldAttrEntity.setRemove(null);
                                fieldAttrEntity.setRemoveAdvanceEnable(null);
                                fieldAttrEntity.setShowRemove(null);
                                fieldAttrEntity.setMultiple(null);
                                fieldAttrEntity.setIsForbidden(null);
                                fieldAttrEntity.setUnableEditMemo(null);
                                fieldAttrEntity.setAddRule(null);
                                fieldAttrEntity.setRemoveRule(null);
                            }
                        }
                    }

                    String explains = JSON.toJSONString(fieldAttrList);
                    explainEntity.setExplains(explains);
                    updateExplains.add(explainEntity);
                }
                if (CollectionsUtil.isNotEmpty(updateExplains)) {
                    paasFormExplainModel.updateBatchExplains(updateExplains);
                }
            }
            LOG.warn("-----------time consume rollBackFixTeamMembersField:{}", (DateTimeUtil.getInt() - timeStart));
            LOG.warn("-----------/script/fund/sheet/explains/rollBackFixTeamMembersField over");
        }catch (Exception e) {
            LOG.error("/script/fund/sheet/explains/rollBackFixTeamMembersField error", e);
        }
        return JSON.toJSONString("{\"msg\":\"success\"}");
    }


    /**
     * 强制把有改动的表单模板默认解释从缓存移除
     * @param businessTypeList
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    private void removeDefaultExplainRedis(List<Integer> businessTypeList) {
        String corpid = "0";
        String other = "_" + DistributorMarkEnum.OTHER.getCode();
        for (Integer businessType : businessTypeList) {
            String redisKey = corpid + "_" + businessType;
            paasRedisHelper.removeValue(RedisPrefixConstant.FIELD_EXPLANATION, redisKey);
            String redisKeyOther = redisKey + other;
            paasRedisHelper.removeValue(RedisPrefixConstant.FIELD_EXPLANATION, redisKeyOther);
        }
    }


    /**
     * 迁移paas表单中的负责人数据，支持增量
     *
     * @param teamMembersDTO
     * @return
     */
    @RequestMapping(value = "/migratePaasFormDataOwner", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String migratePaasFormDataOwner(@RequestBody @Valid TeamMembersDTO teamMembersDTO) throws XbbException {
        try {
            //验证码
            if(!proBaseConfig.getXbbCode().equals(teamMembersDTO.getXbbCode())){
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100006, SystemErrorCodeEnum.API_ERROR_100006.getMsg());
            }
            Long updateTimeStart = teamMembersDTO.getUpdateTimeStart();
            Long updateTimeEnd = teamMembersDTO.getUpdateTimeEnd();
            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            //后置脚本的话updateTimeStart要有值
            param.put("updateTimeStart", updateTimeStart);
            //前置脚本的话updateTimeEnd要有值
            param.put("updateTimeEnd", updateTimeEnd);
            Long maxId = paasFormDataModel.getMaxId(param);
            //每次查询10000条
            Integer pageNum = 10000;
            Long idGte = 0L;
            Integer start = 0;
            param.put("start", start);
            param.put("pageNum", pageNum);
            param.put("orderByStr", "id asc");
            long timeStart = DateTimeUtil.getInt();
            while (true) {
                param.put("idGte", idGte);
                LOG.warn("处理进度：已处理到 .id " + idGte + " / " + maxId);
                List<PaasFormDataNoDataPojo> paasFormDataNoDataPojos = paasFormDataModel.getPaasFormDataNoDataPojo(param);
                if (CollectionsUtil.isEmpty(paasFormDataNoDataPojos)) {
                    break;
                }
                idGte = paasFormDataNoDataPojos.get(paasFormDataNoDataPojos.size() - 1).getId();
                Set<String> ownerIdList = new HashSet<>();
                List<Long> shouldUpdateIdList = new ArrayList<>();
                List<PaasUserEntity> shouldUpdateUserList = new ArrayList<>();
                Map<Long, PaasUserEntity> shouldUpdateUserMap = new HashMap<>();
                //代表是后置的，可能需要更新的数据
                for (PaasFormDataNoDataPojo paasFormDataNoDataPojo : paasFormDataNoDataPojos) {
                    ownerIdList.add(StringUtil.isNotEmpty(paasFormDataNoDataPojo.getOwnerId()) ? paasFormDataNoDataPojo.getOwnerId() : paasFormDataNoDataPojo.getCreatorId());
                    if (Objects.nonNull(updateTimeStart) &&
                            (paasFormDataNoDataPojo.getAddTime() < updateTimeStart && paasFormDataNoDataPojo.getUpdateTime() > updateTimeStart)) {
                        shouldUpdateIdList.add(paasFormDataNoDataPojo.getId());
                    }
                }
                if (CollectionsUtil.isNotEmpty(shouldUpdateIdList)) {
                    Map<String, Object> paasUserMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                    paasUserMap.put("dataIdIn", shouldUpdateIdList);
                    shouldUpdateUserList = paasUserModel.findEntitys(paasUserMap);
                    //因为paas表单一条数据只会对应一个负责人
                    shouldUpdateUserMap = shouldUpdateUserList.stream().collect(Collectors.toMap(PaasUserEntity::getDataId, a -> a,(k1,k2)->k1));
                }
                /*Map<String, UserEntity> userEntityMap = new HashMap<>(ownerIdList.size() * 2);
                if (CollectionsUtil.isNotEmpty(ownerIdList)) {
                    Map<String, Object> ownerMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                    ownerMap.put(ParameterConstant.COLUMNS, "id, corpid, user_id, name, avatar");
                    ownerMap.put("userIdIn", ownerIdList);
                    List<UserEntity> userEntityList = userModel.findEntitys(ownerMap);
                    //多个不同的corpid可能会存在相同的userId,所以下面的map中的key用corpid+userid确定唯一
                    if (CollectionsUtil.isNotEmpty(userEntityList)) {
                        for (UserEntity userEntity : userEntityList) {
                            String key = String.format(SymbolConstant.UNDERLINE_PLACE, userEntity.getCorpid(), userEntity.getUserId());
                            userEntityMap.put(key, userEntity);
                        }
                    }

                }*/
                //拼接最后需要返回的列表
                List<PaasUserEntity> paasUserInsertEntities = new ArrayList<>();
                List<PaasUserEntity> paasUserUpdateEntities = new ArrayList<>();
                for (PaasFormDataNoDataPojo paasFormDataNoDataPojo : paasFormDataNoDataPojos) {
                    Long id = paasFormDataNoDataPojo.getId();
                   /*UserEntity userEntity = userEntityMap.get(String.format(SymbolConstant.UNDERLINE_PLACE, corpid, ownerId));
                    if (Objects.isNull(userEntity)) {
                        LOG.error("paas表单id===:{}，paas表单ownerId===:{}",id, ownerId);
                        return "false";
                    }*/
                    if (Objects.nonNull(updateTimeEnd)) {
                        //代表是前置
                        PaasUserEntity paasUserEntity = packageInsertEntity(paasFormDataNoDataPojo);
                        paasUserInsertEntities.add(paasUserEntity);
                    }else if (Objects.nonNull(updateTimeStart)) {
                        //要分一下插入和更新列表
                        if (paasFormDataNoDataPojo.getAddTime() < updateTimeStart && paasFormDataNoDataPojo.getUpdateTime() > updateTimeStart) {
                            //代表更新
                            PaasUserEntity paasUserEntity = shouldUpdateUserMap.get(id);
                            if (Objects.isNull(paasUserEntity)) {
                                PaasUserEntity newPaasUserEntity = packageInsertEntity(paasFormDataNoDataPojo);
                                paasUserInsertEntities.add(newPaasUserEntity);
                            }else {
                                packageUpdateEntity(paasFormDataNoDataPojo, paasUserEntity);
                                paasUserUpdateEntities.add(paasUserEntity);
                            }
                        }else {
                            //代表插入
                            PaasUserEntity paasUserEntity = packageInsertEntity(paasFormDataNoDataPojo);
                            paasUserInsertEntities.add(paasUserEntity);
                        }
                    }
                   
                }
                if (CollectionsUtil.isNotEmpty(paasUserInsertEntities)) {
                    paasUserModel.insertNoEsBatch(paasUserInsertEntities);
                }
                if (CollectionsUtil.isNotEmpty(paasUserUpdateEntities)) {
                    paasUserModel.updateBatch(paasUserUpdateEntities);
                }
                
            }
            LOG.info("-----------time end:" + (DateTimeUtil.getInt() - timeStart));
            LOG.info("-----------/script/teamMembers/migratePaasFormDataOwner over");
        }catch (Exception e) {
            LOG.error("migratePaasFormDataOwner error:{}", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return "success" ;
    }

    /**
     * 修改paas团队数据
     *
     * @param teamMembersDTO
     * @return
     * @throws XbbException
     */
    @RequestMapping(value = "/fixPaasTeam", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fixPaasTeam(@RequestBody @Valid TeamMembersDTO teamMembersDTO) throws XbbException{
        //验证码
        if(!proBaseConfig.getXbbCode().equals(teamMembersDTO.getXbbCode())){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100006, SystemErrorCodeEnum.API_ERROR_100006.getMsg());
        }
        List<String> corpidList = teamMembersDTO.getCorpidList();
        if (CollectionsUtil.isEmpty(corpidList)) {
            //需要处理的有工作流并且有paas表单的公司
            corpidList = companyConfigModel.getPaasAndWorkflowCorpList();
        }
        Map<String, Object> param = new HashMap<>();
        Long updateTimeStart = teamMembersDTO.getUpdateTimeStart();
        param.put("updateTimeStart", updateTimeStart);
        long timeStart = DateTimeUtil.getInt();
        LOG.info("总共有多少家需要处理的公司:{}", corpidList.size());
        Map<String, Object> paasFormDataParam = new HashMap<>();
        paasFormDataParam.put("del", BasicConstant.ZERO);
        int i = 0;
        for (String corpid : corpidList) {
            try {
                //只查询删除的数据，因为只有这些数据才会有问题
                param.remove("dataIdIn");
                param.put("del", BasicConstant.ONE);
                i++;
                LOG.info("现在是第{}家公司, corpid:{}", i, corpid);
                param.put("corpid", corpid);
                List<PaasUserEntity> paasUserEntities = paasUserModel.findEntitys(param);
                if (CollectionsUtil.isEmpty(paasUserEntities)) {
                    continue;
                }
                LOG.info("第一步骤:{}", paasUserEntities.size());
                List<Long> idS = paasUserEntities.stream().map(PaasUserEntity::getDataId).distinct().collect(Collectors.toList());
                Map<Long, List<PaasUserEntity>> paasUserMap = paasUserEntities.stream().collect(Collectors.groupingBy(PaasUserEntity::getDataId));
                //再根据查询出来的paas的dataId去查询这些dataId有没有正常的del=0的正常数据
                param.put("dataIdIn", idS);
                param.put("del", BasicConstant.ZERO);
                param.put("columns", "data_id, del");
                List<PaasUserEntity> ordinaryPaasUserList = paasUserModel.findEntitys(param);
                List<Long> ordinaryIdList = new ArrayList<>();
                if (CollectionsUtil.isNotEmpty(ordinaryPaasUserList)) {
                    ordinaryIdList = ordinaryPaasUserList.stream().map(PaasUserEntity::getDataId).collect(Collectors.toList());
                }
                LOG.info("第二步骤:{}", ordinaryIdList.size());
                List<Long> shouldPaasDataIdList = new ArrayList<>();
                Iterator<Map.Entry<Long, List<PaasUserEntity>>> iterator =  paasUserMap.entrySet().iterator();
                while (iterator.hasNext()) {
                    Map.Entry<Long, List<PaasUserEntity>> entry = iterator.next();
                    if (ordinaryIdList.contains(entry.getKey())) {
                        iterator.remove();
                    }else {
                        shouldPaasDataIdList.add(entry.getKey());
                    }
                }
                //剩下就是需要处理的数据
                paasFormDataParam.put("corpid", corpid);
                paasFormDataParam.put("idIn", shouldPaasDataIdList);
                paasFormDataParam.put("columns", "id, del");
                List<PaasFormDataEntityExt> paasFormDataEntityExts = paasFormDataModel.findEntityOriginal(paasFormDataParam);
                if (CollectionsUtil.isEmpty(paasFormDataEntityExts)) {
                    continue;
                }
                LOG.info("第三步骤:{}", paasFormDataEntityExts.size());
                Map<Long, Integer> data2delMap = paasFormDataEntityExts.stream().collect(Collectors.toMap(PaasFormDataEntityExt::getId, PaasFormDataEntityExt::getDel));
                //更新paas团队数据
                List<UserTeamEntity> teamEntityList = new ArrayList<>();
                List<Long> idList = new ArrayList<>();
                for (PaasUserEntity paasUserEntity : paasUserEntities) {
                    Long dataId = paasUserEntity.getDataId();
                    if (!shouldPaasDataIdList.contains(dataId)) {
                        continue;
                    }
                    if (data2delMap.containsKey(dataId)) {
                        Integer del = data2delMap.get(dataId);
                        if (Objects.equals(BasicConstant.ZERO, del)) {
                            //这些代表需要更新的数据
                            UserTeamEntity userTeamEntity = new UserTeamEntity();
                            BeanUtil.copyProperties(paasUserEntity, userTeamEntity);
                            userTeamEntity.setDel(BasicConstant.ONE);
                            teamEntityList.add(userTeamEntity);
                            idList.add(paasUserEntity.getId());
                        }
                    }
                }
                if (CollectionsUtil.isNotEmpty(teamEntityList)) {
                    paasUserModel.batchUpdateByUserIdIn(corpid, idList, teamEntityList, null, BasicConstant.ZERO);
                }
            }catch (Exception e) {
                LOG.error("异常：{}, corpid:{}", e, corpid);
            }
        }
        LOG.info("-----------time consume fixPaasTeam:" + (DateTimeUtil.getInt() - timeStart));
        return JSON.toJSONString("{\"msg\":\"success\"}");
    }



    /**
     * 封装需要插入的实体
     *
     * @param paasFormDataNoDataPojo 主表数据
     * @return
     */
    private PaasUserEntity packageInsertEntity(PaasFormDataNoDataPojo paasFormDataNoDataPojo) {
        PaasUserEntity paasUserEntity = new PaasUserEntity();
        paasUserEntity.setCorpid(paasFormDataNoDataPojo.getCorpid());
        paasUserEntity.setDataId(paasFormDataNoDataPojo.getId());
        paasUserEntity.setUserId(paasFormDataNoDataPojo.getOwnerId());
        paasUserEntity.setIsMain(BasicConstant.ONE);
        paasUserEntity.setUserName(null);
        paasUserEntity.setUserAvatar(null);
        paasUserEntity.setAddTime(paasFormDataNoDataPojo.getAddTime());
        paasUserEntity.setUpdateTime(paasFormDataNoDataPojo.getUpdateTime());
        paasUserEntity.setDel(paasFormDataNoDataPojo.getDel());
        return paasUserEntity;
    }

    /**
     * 封装需要更新的实体
     *
     * @param paasFormDataNoDataPojo 主表数据
     * @param paasUserEntity paas团队表存在的数据
     * @return
     */
    private void packageUpdateEntity(PaasFormDataNoDataPojo paasFormDataNoDataPojo, PaasUserEntity paasUserEntity) {
        paasUserEntity.setUserId(paasFormDataNoDataPojo.getOwnerId());
        paasUserEntity.setUpdateTime(paasFormDataNoDataPojo.getUpdateTime());
        paasUserEntity.setDel(paasFormDataNoDataPojo.getDel());
    }


}
